<?php
!function_exists('adminmsg') && exit('Forbidden');
InitGP(array('hid'),'2');
empty($hid) && adminmsg('undefined_action');
$_basename	= $basename.'&action=information&hid='.$hid;
InitGP(array('type'));
$models = array(
	'flash' =>array(
		'model' => 'flash',
		'name'	=> '图片播放器',
		'type'	=> 'image',
	),
	'newinfor' =>array(
		'model' => 'newinfor',
		'name'	=> '楼盘最新资讯',
		'relate'=> 'tags',
		'type'	=> 'subject',
	),
	'newreply' =>array(
		'model' => 'newreply',
		'name'	=> '业主小区最新讨论',
		'type'	=> 'subject',
	),
);
$service = House::loadClass('pushdataservice','service');
if (!$type) {
	$ajax_basename = EncodeUrl($_basename);
	require_once PrintMode('information');
} elseif ($type=='modelcotent') {
	InitGP(array('model','page'));
	$ajax_basename = EncodeUrl($_basename);
	$pushs = $service->getModelPushs($hid,$model,$page,10);
	$pages = $service->getPushDataPages($hid,$model,$page,"$_basename&type=modelcotent&model=$model&",10);
	require_once PrintMode('information');
} elseif ($type=='add') {
	InitGP(array('model','step','pushkey'));
	define('AJAX', 1);
	if (!$step) {
		$ajax_basename = EncodeUrl($_basename);
		if ($models[$model]['type']=='image') {
			if ($pushkey) {
				$imageService = House::loadClass('houseimage'); /* @var $imageService PW_HouseImage */
				$temp = $imageService->getImage($pushkey);
				$default = array('title'=>substrs($temp['descrip'],6,false),'image'=>$temp['path'],'url'=>$temp['url']);
			}
			require_once PrintMode('ajax_push_image');
		} else {
			require_once PrintMode('ajax_push');
		}
	} else {
		InitGP(array('title','url','offset','select_imagetype'));
		//$attachpath
		
		
		if ($models[$model]['type']=='image') {
			InitGP(array('image'));
			if($select_imagetype == 1){
				require_once(M_P . 'lib/model/playerupload.class.php');
				$img = new PlayerUpload($hid,'house/nature/','house/mini/');
				PwUpload::upload($img);
				$image = $attachpath."/".($img->attachs['fileuploadurl']);
			}
			$temp = array('title'=>$title,'url'=>$url,'image'=>$image,'offset'=>$offset,'author'=>$admin_name);
		} else {
			InitGP(array('css'));
			$temp = array('title'=>$title,'url'=>$url,'titlecss'=>$css,'offset'=>$offset,'author'=>$admin_name);
		}
		$result = $service->addPushData($hid,$model,$temp);
		if ($result) {
			echo getLangInfo('msg','operate_success')."\treload";
		} else {
			Showmsg('undefined_action');
		}
	}
	ajax_footer();
} elseif ($type=='edit') {
	InitGP(array('step','id'));
	define('AJAX', 1);
	$push = $service->getPush($id);
	$model = $push['model'];
	if (!$step) {
		$ajax_basename = EncodeUrl($_basename);
		
		if ($models[$model]['type']=='image') {
			require_once PrintMode('ajax_push_image');
		} else {
			$titlecolor	= $push['titlecss']['color'];
			if ($titlecolor && !preg_match('/\#[0-9A-F]{6}/is',$titlecolor)) {
				$titlecolor = '';
			}
			if ($push['titlecss']['b']=='1') {
				$stylename[1]='b one';
			} else {
				$stylename[1]='b';
			}
			if ($push['titlecss']['u']=='1') {
				$stylename[3]='u one';
			} else {
				$stylename[3]='u';
			}
			if ($push['titlecss']['i']=='1') {
				$stylename[2]='one';
			} else {
				$stylename[2]='';
			}
			require_once PrintMode('ajax_push');
		}
	} else {
		InitGP(array('title','url','offset','image','select_imagetype'));
		if ($models[$model]['type']=='image') {
			InitGP(array('image'));
			if($select_imagetype == 1){
				require_once(M_P . 'lib/model/playerupload.class.php');
				$img = new PlayerUpload($hid,'house/nature/','house/mini/');
				PwUpload::upload($img);
				$image = $attachpath."/".($img->attachs['fileuploadurl']);
			}
			$image = str_replace('\\','/',$image);
			$temp = array('title'=>$title,'url'=>$url,'image'=>$image,'offset'=>$offset,'author'=>$admin_name);
		} else {
			InitGP(array('css'));
			$temp = array('title'=>$title,'url'=>$url,'titlecss'=>$css,'offset'=>$offset,'author'=>$admin_name);
		}
		$result = $service->editPushData($id,$temp);
		
		echo getLangInfo('msg','operate_success')."\treload";
	}
	ajax_footer();
} elseif ($type=='delpush') {
	InitGP(array('id'),'',2);
	define('AJAX', 1);
	$service->deletePushData($id);
	echo getLangInfo('msg','operate_success')."\treload";
	ajax_footer();
} elseif ($type=='relate') {
	InitGP(array('model'));
	define('AJAX', 1);
	$relateType = $models[$model]['relate'];
	if (file_exists(M_P.'admin/information_'.$relateType.'.php')) {
		require Pcv(M_P.'admin/information_'.$relateType.'.php');
	}
	ajax_footer();
} elseif (in_array($type,array('deletes','open','close'))) {
	InitGP(array('selid','model'));
	if (!$selid) {
		adminmsg('请选择要操作的内容',$_basename.'&type=modelcotent&model='.$model);
	}
	switch ($type) {
		case 'deletes' :
			$service->deletePushDatas($selid);
			break;
		case 'open';
			$service->setOpens($selid);
			break;
		case 'close';
			$service->setCloses($selid);
			break;
	}

	adminmsg('operate_success',$_basename."&type=modelcotent&model=$model");
}
?>